﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Vit.Common;
using Vit.Web;
using Vit.Web.Models;
using Vit.Web.Providers.Data;

namespace Vit.AdminModule.Areas.Admin.Providers
{
    public class SqlRoleDataProvider : DbContextDataProvider<WebProvidersDb, Role>
    {

        protected override IQueryable<Role> OrderByDefault(IQueryable<Role> query)
        {
            return query.OrderBy(o => o.Name);
        }

        public override object[] GetKeys(Role obj)
        {
            return new object[] { obj.Name };
        }

        public override Role GetByKeys(params object[] ids)
        {
            if (ids == null || ids.Length != 1)
                return null;
            string key = ids[0].ToString();
            return db.Roles.FirstOrDefault(o => o.Name == key);
        }
    }
}
